Skip to content

Commit c036b91

Browse files
add --extra-ldflags;
support commas in configure file support link system library for utest
1 parent 4372e32 commit c036b91

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

trunk/auto/options.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ SRS_TOOL_AR=ar
119119
SRS_TOOL_LD=ld
120120
SRS_TOOL_RANDLIB=randlib
121121
SRS_EXTRA_FLAGS=
122+
SRS_EXTRA_LDFLAGS=
122123
#
123124
#####################################################################################
124125
# Performance optimize.
@@ -209,6 +210,7 @@ Toolchain options:
209210
--ld=<LD> Toolchain: Use linker tool LD. Default: $SRS_TOOL_CXX
210211
--randlib=<RANDLIB> Toolchain: Use randlib tool RANDLIB. Default: $SRS_TOOL_CXX
211212
--extra-flags=<EFLAGS> Set EFLAGS as CFLAGS and CXXFLAGS. Also passed to ST as EXTRA_CFLAGS.
213+
--extra-ldflags=<ELDFLAGS> Set ELDFLAGS as LDFLAGS.
212214
213215
Cross Build options: @see https://ossrs.net/lts/zh-cn/docs/v4/doc/arm#ubuntu-cross-build-srs
214216
--cross=on|off Enable cross-build, please set bellow Toolchain also. Default: $(value2switch $SRS_CROSS_BUILD)
@@ -313,6 +315,7 @@ function parse_user_option() {
313315
--ld) SRS_TOOL_LD=${value} ;;
314316
--randlib) SRS_TOOL_RANDLIB=${value} ;;
315317
--extra-flags) SRS_EXTRA_FLAGS=${value} ;;
318+
--extra-ldflags) SRS_EXTRA_LDFLAGS=${value} ;;
316319
--build-tag) SRS_BUILD_TAG=${value} ;;
317320

318321
--srtp-nasm) SRS_SRTP_ASM=$(switch2value $value) ;;
@@ -442,7 +445,7 @@ function parse_user_option_to_value_and_option() {
442445
case "$option" in
443446
-*=*)
444447
value=`echo "$option" | sed -e 's|[-_a-zA-Z0-9/]*=||'`
445-
option=`echo "$option" | sed -e 's|=[-_a-zA-Z0-9/. +]*||'`
448+
option=`echo "$option" | sed -e 's|=[,-_a-zA-Z0-9/. +]*||'`
446449
;;
447450
*) value="" ;;
448451
esac
@@ -684,6 +687,7 @@ function regenerate_options() {
684687
if [[ $SRS_CROSS_BUILD_HOST != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --host=$SRS_CROSS_BUILD_HOST"; fi
685688
if [[ $SRS_CROSS_BUILD_PREFIX != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --cross-prefix=$SRS_CROSS_BUILD_PREFIX"; fi
686689
if [[ $SRS_EXTRA_FLAGS != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --extra-flags=\\\"$SRS_EXTRA_FLAGS\\\""; fi
690+
if [[ $SRS_EXTRA_LDFLAGS != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --extra-ldflags=\\\"$SRS_EXTRA_LDFLAGS\\\""; fi
687691
if [[ $SRS_BUILD_TAG != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --build-tag=\\\"$SRS_BUILD_TAG\\\""; fi
688692
if [[ $SRS_TOOL_CC != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cc=$SRS_TOOL_CC"; fi
689693
if [[ $SRS_TOOL_CXX != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx=$SRS_TOOL_CXX"; fi

trunk/configure

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ END
145145
# header(.h): add to ModuleLibIncs if need the specified library. for example, LibSTRoot
146146
# library(.a): add to ModuleLibFiles if binary need the specifeid library. for example, LibSTfile
147147
#
148+
149+
# the link options, always use static link
150+
SrsLinkOptions="-ldl -lpthread";
151+
148152
# st(state-threads) the basic network library for SRS.
149153
LibSTRoot="${SRS_OBJS}/st"; LibSTfile="${LibSTRoot}/libst.a"
150154
if [[ $SRS_SHARED_ST == YES ]]; then LibSTfile="-L${LibSTRoot} -lst"; fi
@@ -154,7 +158,10 @@ if [[ $SRS_RTC == YES ]]; then
154158
LibSrtpRoot="${SRS_OBJS}/srtp2/include"; LibSrtpFile="${SRS_OBJS}/srtp2/lib/libsrtp2.a"
155159
if [[ $SRS_USE_SYS_SRTP == YES ]]; then
156160
LibSrtpRoot=""; LibSrtpFile="libsrtp2.a"
157-
if [[ $SRS_SHARED_SRTP == YES ]]; then LibSrtpFile="-lsrtp2"; fi
161+
if [[ $SRS_SHARED_SRTP == YES ]]; then
162+
LibSrtpFile="";
163+
SrsLinkOptions="${SrsLinkOptions} -lsrtp2";
164+
fi
158165
fi
159166
fi
160167

@@ -175,7 +182,8 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then
175182
LibFfmpegRoot=""
176183
LibFfmpegFile="libavcodec.a libswresample.a libavutil.a libopus.a";
177184
if [[ $SRS_SHARED_FFMPEG == YES ]]; then
178-
LibFfmpegFile="-lavcodec -lswresample -lavutil -lopus"
185+
LibFfmpegFile=""
186+
SrsLinkOptions="${SrsLinkOptions} -lavcodec -lswresample -lavutil -lopus";
179187
fi
180188
fi
181189
fi
@@ -201,12 +209,13 @@ if [[ $SRS_SRT == YES ]]; then
201209
if [[ $SRS_SHARED_SRT == YES ]]; then LibSRTfile="-L${SRS_OBJS}/srt/lib -lsrt"; fi
202210
if [[ $SRS_USE_SYS_SRT == YES ]]; then
203211
LibSRTRoot=""; LibSRTfile="libsrt.a"
204-
if [[ $SRS_SHARED_SRT == YES ]]; then LibSRTfile="-lsrt"; fi
212+
if [[ $SRS_SHARED_SRT == YES ]]; then
213+
LibSRTfile="";
214+
SrsLinkOptions="${SrsLinkOptions} -lsrt";
215+
fi
205216
fi
206217
fi
207218

208-
# the link options, always use static link
209-
SrsLinkOptions="-ldl -lpthread";
210219
if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
211220
SrsLinkOptions="${SrsLinkOptions} -lssl -lcrypto";
212221
fi
@@ -247,6 +256,11 @@ if [[ $SRS_CYGWIN64 == YES && $SRS_FFMPEG_FIT == YES ]]; then
247256
SrsLinkOptions="${SrsLinkOptions} -lbcrypt";
248257
fi
249258

259+
# User configed options.
260+
if [[ $SRS_EXTRA_LDFLAGS != '' ]]; then
261+
SrsLinkOptions="${SrsLinkOptions} $SRS_EXTRA_LDFLAGS";
262+
fi
263+
250264
#####################################################################################
251265
# Modules, compile each module, then link to binary
252266
#
@@ -415,7 +429,7 @@ if [[ $SRS_SRT == YES ]]; then
415429
ModuleLibIncs+=(${LibSRTRoot})
416430
MODULE_OBJS="${MODULE_OBJS} ${SRT_OBJS[@]}"
417431
fi
418-
LINK_OPTIONS="${SrsLinkOptions}${SrsGprofLink}${SrsGperfLink}"
432+
LINK_OPTIONS="${LDFLAGS} ${SrsLinkOptions}${SrsGprofLink}${SrsGperfLink}"
419433
#
420434
# srs: srs(simple rtmp server) over st(state-threads)
421435
BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . $SRS_WORKDIR/auto/apps.sh
@@ -479,7 +493,7 @@ if [[ $SRS_UTEST == YES ]]; then
479493
fi
480494
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
481495
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${SRT_OBJS[@]}"
482-
LINK_OPTIONS="-lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . $SRS_WORKDIR/auto/utest.sh
496+
LINK_OPTIONS="${LDFLAGS} -lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . $SRS_WORKDIR/auto/utest.sh
483497
fi
484498

485499
#####################################################################################
@@ -506,6 +520,7 @@ AR = ${SRS_TOOL_AR}
506520
LINK = ${SRS_TOOL_LD}
507521
RANDLIB = ${SRS_TOOL_RANDLIB}
508522
CXXFLAGS = ${CXXFLAGS}
523+
LDFLAGS = ${LDFLAGS}
509524
510525
# install prefix.
511526
SRS_PREFIX=${SRS_PREFIX}

0 commit comments

Comments
 (0)