Skip to content

Commit 0df1087

Browse files
committed
Fix #1547, support crossbuild for ARM/MIPS.
1 parent 6af8e38 commit 0df1087

File tree

6 files changed

+73
-30
lines changed

6 files changed

+73
-30
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ For previous versions, please read:
146146

147147
## V3 changes
148148

149-
* v3.0, 2020-01-21, For [#1547][bug #1547], support setting cc/cxx/ar tools. 3.0.103
149+
* v3.0, 2020-01-21, Fix [#1547][bug #1547], support crossbuild for ARM/MIPS.
150+
* v3.0, 2020-01-21, For [#1547][bug #1547], support setting cc/cxx/ar/ld/randlib tools. 3.0.103
150151
* v3.0, 2020-01-19, For [#1580][bug #1580], fix cid range problem. 3.0.102
151152
* v3.0, 2020-01-19, For [#1070][bug #1070], define FLV CodecID for [AV1][bug #1070] and [opus][bug #307]. 3.0.101
152153
* v3.0, 2020-01-16, For [#1575][bug #1575], correct RTMP redirect as tcUrl, add redirect2 as RTMP URL. 3.0.100

trunk/auto/auto_headers.sh

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ if [ $SRS_LOG_TRACE = YES ]; then
132132
else
133133
srs_undefine_macro "SRS_AUTO_TRACE" $SRS_AUTO_HEADERS_H
134134
fi
135+
if [ $SRS_CROSS_BUILD = YES ]; then
136+
srs_define_macro "SRS_AUTO_CROSSBUILD" $SRS_AUTO_HEADERS_H
137+
else
138+
srs_undefine_macro "SRS_AUTO_CROSSBUILD" $SRS_AUTO_HEADERS_H
139+
fi
135140

136141
# prefix
137142
echo "" >> $SRS_AUTO_HEADERS_H

trunk/auto/depends.sh

+33-28
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
232232
(
233233
rm -rf ${SRS_OBJS}/st-srs && cd ${SRS_OBJS} &&
234234
ln -sf ../3rdparty/st-srs && cd st-srs &&
235-
make clean && make ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" &&
235+
make clean && make ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" \
236+
CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} &&
236237
cd .. && rm -f st && ln -sf st-srs/obj st
237238
)
238239
fi
@@ -321,38 +322,43 @@ fi
321322
#####################################################################################
322323
# openssl, for rtmp complex handshake
323324
#####################################################################################
324-
# extra configure options
325-
OPENSSL_HOTFIX="-DOPENSSL_NO_HEARTBEATS"
325+
if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
326+
echo "Warning: Use system libssl, without compiling openssl."
327+
fi
326328
# @see http://www.openssl.org/news/secadv/20140407.txt
327329
# Affected users should upgrade to OpenSSL 1.1.0e. Users unable to immediately
328330
# upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
329-
if [ $SRS_SSL = YES ]; then
330-
if [[ -f /usr/local/lib64/libssl.a && ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
331-
(mkdir -p ${SRS_OBJS}/openssl/lib && cd ${SRS_OBJS}/openssl/lib &&
332-
ln -sf /usr/local/lib64/libssl.a && ln -sf /usr/local/lib64/libcrypto.a)
333-
(mkdir -p ${SRS_OBJS}/openssl/include && cd ${SRS_OBJS}/openssl/include &&
334-
ln -sf /usr/local/include/openssl)
335-
fi
336-
if [ $SRS_USE_SYS_SSL = YES ]; then
337-
echo "Warning: Use system libssl, without compiling openssl."
331+
if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then
332+
OPENSSL_HOTFIX="-DOPENSSL_NO_HEARTBEATS"
333+
OPENSSL_CONFIG="./config"
334+
# https://stackoverflow.com/questions/15539062/cross-compiling-of-openssl-for-linux-arm-v5te-linux-gnueabi-toolchain
335+
if [[ $SRS_CROSS_BUILD == YES ]]; then
336+
OPENSSL_CONFIG="./Configure linux-armv4"
338337
else
339-
# cross build not specified, if exists flag, need to rebuild for no-arm platform.
340-
if [[ -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
341-
echo "Openssl-1.1.0e is ok.";
342-
else
343-
echo "Building openssl-1.1.0e.";
344-
(
345-
rm -rf ${SRS_OBJS}/openssl-1.1.0e && cd ${SRS_OBJS} &&
346-
unzip -q ../3rdparty/openssl-1.1.0e.zip && cd openssl-1.1.0e &&
347-
./config --prefix=`pwd`/_release -no-shared no-threads $OPENSSL_HOTFIX &&
348-
make && make install_sw &&
349-
cd .. && rm -rf openssl && ln -sf openssl-1.1.0e/_release openssl
350-
)
338+
# If not crossbuild, try to use exists libraries.
339+
if [[ -f /usr/local/lib64/libssl.a && ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
340+
(mkdir -p ${SRS_OBJS}/openssl/lib && cd ${SRS_OBJS}/openssl/lib &&
341+
ln -sf /usr/local/lib64/libssl.a && ln -sf /usr/local/lib64/libcrypto.a)
342+
(mkdir -p ${SRS_OBJS}/openssl/include && cd ${SRS_OBJS}/openssl/include &&
343+
ln -sf /usr/local/include/openssl)
351344
fi
352-
# check status
353-
ret=$?; if [[ $ret -ne 0 ]]; then echo "Build openssl-1.1.0e failed, ret=$ret"; exit $ret; fi
354-
if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "Build openssl-1.1.0e failed."; exit -1; fi
355345
fi
346+
# cross build not specified, if exists flag, need to rebuild for no-arm platform.
347+
if [[ -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
348+
echo "Openssl-1.1.0e is ok.";
349+
else
350+
echo "Building openssl-1.1.0e.";
351+
(
352+
rm -rf ${SRS_OBJS}/openssl-1.1.0e && cd ${SRS_OBJS} &&
353+
unzip -q ../3rdparty/openssl-1.1.0e.zip && cd openssl-1.1.0e &&
354+
${OPENSSL_CONFIG} --prefix=`pwd`/_release -no-shared -no-threads -no-asm $OPENSSL_HOTFIX &&
355+
make CC=${SRS_TOOL_CC} AR="${SRS_TOOL_AR} -rs" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} && make install_sw &&
356+
cd .. && rm -rf openssl && ln -sf openssl-1.1.0e/_release openssl
357+
)
358+
fi
359+
# check status
360+
ret=$?; if [[ $ret -ne 0 ]]; then echo "Build openssl-1.1.0e failed, ret=$ret"; exit $ret; fi
361+
if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "Build openssl-1.1.0e failed."; exit -1; fi
356362
fi
357363

358364
#####################################################################################
@@ -447,4 +453,3 @@ fi
447453
# generated the test script
448454
#####################################################################################
449455
rm -rf ${SRS_OBJS}/srs.test && ln -sf `pwd`/scripts/srs.test objs/srs.test
450-

trunk/auto/options.sh

+24
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ SRS_CROSS_BUILD=NO
100100
SRS_TOOL_CC=gcc
101101
SRS_TOOL_CXX=g++
102102
SRS_TOOL_AR=ar
103+
SRS_TOOL_LD=ld
104+
SRS_TOOL_RANDLIB=randlib
103105
SRS_EXTRA_FLAGS=
104106

105107
#####################################################################################
@@ -164,6 +166,8 @@ Toolchain options: @see https://github.com/ossrs/srs/issues/1547#issuec
164166
--cc=<CC> Use c compiler CC, default is gcc.
165167
--cxx=<CXX> Use c++ compiler CXX, default is g++.
166168
--ar=<AR> Use archive tool AR, default is ar.
169+
--ld=<LD> Use linker tool LD, default is ld.
170+
--randlib=<RANDLIB> Use randlib tool RANDLIB, default is randlib.
167171
--extra-flags=<EFLAGS> Set EFLAGS as CFLAGS and CXXFLAGS. Also passed to ST as EXTRA_CFLAGS.
168172
169173
Conflicts:
@@ -249,6 +253,8 @@ function parse_user_option() {
249253
--cc) SRS_TOOL_CC=${value} ;;
250254
--cxx) SRS_TOOL_CXX=${value} ;;
251255
--ar) SRS_TOOL_AR=${value} ;;
256+
--ld) SRS_TOOL_LD=${value} ;;
257+
--randlib) SRS_TOOL_RANDLIB=${value} ;;
252258
--extra-flags) SRS_EXTRA_FLAGS=${value} ;;
253259

254260
--x86-x64) SRS_X86_X64=YES ;;
@@ -420,6 +426,14 @@ function apply_user_presets() {
420426
SRS_UTEST=NO
421427
SRS_STATIC=NO
422428
fi
429+
430+
# if crossbuild, disable research and librtmp.
431+
if [[ $SRS_CROSS_BUILD == YES ]]; then
432+
SRS_LIBRTMP=NO
433+
SRS_RESEARCH=NO
434+
SRS_UTEST=NO
435+
SRS_STATIC=NO
436+
fi
423437
}
424438
apply_user_presets
425439

@@ -520,6 +534,8 @@ SRS_AUTO_CONFIGURE="--prefix=${SRS_PREFIX}"
520534
if [[ $SRS_TOOL_CC != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cc=$SRS_TOOL_CC"; fi
521535
if [[ $SRS_TOOL_CXX != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx=$SRS_TOOL_CXX"; fi
522536
if [[ $SRS_TOOL_AR != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ar=$SRS_TOOL_AR"; fi
537+
if [[ $SRS_TOOL_LD != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ld=$SRS_TOOL_LD"; fi
538+
if [[ $SRS_TOOL_RANDLIB != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --randlib=$SRS_TOOL_RANDLIB"; fi
523539
echo "User config: $SRS_AUTO_USER_CONFIGURE"
524540
echo "Detail config: ${SRS_AUTO_CONFIGURE}"
525541
}
@@ -541,6 +557,14 @@ function check_option_conflicts() {
541557
echo "No arhive tool"
542558
exit -1
543559
fi
560+
if [[ $SRS_TOOL_LD == '' ]]; then
561+
echo "No linker tool"
562+
exit -1
563+
fi
564+
if [[ $SRS_TOOL_RANDLIB == '' ]]; then
565+
echo "No randlib tool"
566+
exit -1
567+
fi
544568

545569
if [ $SRS_OSX = YES ]; then
546570
echo "We don't support OSX, please use docker https://github.com/ossrs/srs-docker"

trunk/src/main/srs_main_server.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ void show_macro_features()
251251
#if defined(__aarch64__)
252252
ss << " aarch64";
253253
#endif
254+
#if defined(SRS_AUTO_CROSSBUILD)
255+
ss << "(crossbuild)";
256+
#endif
254257

255258
ss << ", conf:" << _srs_config->config() << ", limit:" << _srs_config->get_max_connections()
256259
<< ", writev:" << sysconf(_SC_IOV_MAX) << ", encoding:" << (srs_is_little_endian()? "little-endian":"big-endian")

trunk/src/service/srs_service_st.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ srs_error_t srs_fd_reuseport(int fd)
115115
#if defined(SO_REUSEPORT)
116116
int v = 1;
117117
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(int)) == -1) {
118-
return srs_error_new(ERROR_SOCKET_SETREUSEADDR, "SO_REUSEPORT fd=%v", fd);
118+
#ifdef SRS_AUTO_CROSSBUILD
119+
srs_warn("SO_REUSEPORT disabled for crossbuild");
120+
return srs_success;
121+
#else
122+
return srs_error_new(ERROR_SOCKET_SETREUSEADDR, "SO_REUSEPORT fd=%v", fd);
123+
#endif
119124
}
120125
#else
121126
#warning "SO_REUSEPORT is not supported by your OS"

0 commit comments

Comments
 (0)