Skip to content

Commit 5e1947f

Browse files
committed
1.update build.sh for multi argument parsing
2.fix libhash depdency 3.add ASAN check into makefile
1 parent e646926 commit 5e1947f

File tree

14 files changed

+177
-56
lines changed

14 files changed

+177
-56
lines changed

build.sh

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,10 @@
22
set -e
33

44
CMD=$0
5-
MODULE=$1
6-
ARCH=$2
7-
MODE=$3
8-
9-
#default is linux
10-
case $# in
11-
0)
12-
MODULE=all;
13-
ARCH=linux;
14-
MODE=debug;;
15-
1)
16-
ARCH=linux;
17-
MODE=debug;;
18-
2)
19-
MODE=debug;;
20-
21-
esac
5+
MODULE=all
6+
ARCH=linux
7+
MODE=debug
8+
ASAN=0
229

2310

2411
#add supported platform to here
@@ -28,10 +15,12 @@ PLATFORM="[linux|pi|android|ios]"
2815
BASIC_LIBS="libposix libtime liblog libdarray libthread libgevent libworkq libdict libhash libsort \
2916
librbtree libringbuffer libvector libstrex libmedia-io \
3017
libdebug libfile libqueue libplugin libhal libsubmask"
31-
MEDIA_LIBS="libavcap"
18+
MEDIA_LIBS="libavcap libmp4"
3219
FRAMEWORK_LIBS="libipc"
3320
NETWORK_LIBS="libsock libptcp librpc librtsp librtmpc"
3421

22+
23+
3524
usage()
3625
{
3726
echo "==== usage ===="
@@ -66,26 +55,51 @@ usage()
6655
exit
6756
}
6857

69-
config_linux()
70-
{
71-
CROSS_PREFIX=
72-
}
73-
74-
config_pi()
75-
{
76-
CROSS_PREFIX=arm-linux-gnueabihf-
77-
}
78-
79-
config_android()
80-
{
81-
CROSS_PREFIX=arm-linux-androideabi-
82-
}
83-
84-
config_ios()
85-
{
86-
echo "need a mac computer, who can help me :-)"
87-
exit 0;
88-
}
58+
#-o或--options选项后面接可接受的短选项,如ab:c::,表示可接受的短选项为-a -b -c,其中-a选项不接参数,-b选项后必须接参数,-c选项的参数为可选的
59+
#-l或--long选项后面接可接受的长选项,用逗号分开,冒号的意义同短选项。
60+
#-n选项后接选项解析错误时提示的脚本名字
61+
ARGS=`getopt -o a:m:h --long arch:,module:,help,asan: -n 'build.sh' -- "$@"`
62+
if [ $? != 0 ]; then
63+
echo "Terminating..."
64+
exit 1
65+
fi
66+
67+
#将规范化后的命令行参数分配至位置参数($1,$2,...)
68+
eval set -- "${ARGS}"
69+
70+
while true
71+
do
72+
case "$1" in
73+
-h|--help)
74+
usage;
75+
shift
76+
;;
77+
-a|--arch)
78+
ARCH=$2
79+
shift 2
80+
;;
81+
-m|--mode)
82+
MODE=$2
83+
shift 2
84+
;;
85+
--module)
86+
MODULE=$2
87+
shift 2
88+
;;
89+
--asan)
90+
ASAN=$2
91+
shift 2
92+
;;
93+
--)
94+
shift
95+
break
96+
;;
97+
*)
98+
echo "invalid arguments: $@"
99+
exit 1
100+
;;
101+
esac
102+
done
89103

90104
config_common()
91105
{
@@ -98,15 +112,21 @@ config_arch()
98112
{
99113
case $ARCH in
100114
"pi")
101-
config_pi;;
115+
CROSS_PREFIX=arm-linux-gnueabihf-
116+
;;
102117
"android")
103-
config_android;;
118+
CROSS_PREFIX=arm-linux-androideabi-
119+
;;
104120
"linux")
105-
config_linux;;
121+
CROSS_PREFIX=
122+
;;
106123
"ios")
107-
config_ios;;
124+
echo "not support cross compile, should compile native on Mac"
125+
exit 0;
126+
;;
108127
*)
109-
usage;;
128+
echo "arch: $ARCH not supported"
129+
;;
110130
esac
111131
}
112132

@@ -175,12 +195,8 @@ build_module()
175195
;;
176196
*)
177197
echo "==== build ${ARCH} ${MODULE} start..."
178-
MAKE="make ARCH=${ARCH} OUTPUT=${OUTPUT} MODE=${MODE}"
179-
if [[ ${ARCH} == "linux" || ${ARCH} == "pi" || ${ARCH} == "android" ]]; then
180-
${MAKE} > /dev/null
181-
else
182-
echo "${ARCH} not support now" #make -f Makefile.${ARCH} > /dev/null
183-
fi
198+
MAKE="make ARCH=${ARCH} OUTPUT=${OUTPUT} MODE=${MODE} ASAN=${ASAN}"
199+
${MAKE} > /dev/null
184200
if [ $? -ne 0 ]; then
185201
echo "==== build ${ARCH} ${MODULE} failed"
186202
return;

gear-lib/libfile/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ CFLAGS := -g -Wall -Werror -fPIC
5252
LTYPE := debug
5353
endif
5454

55-
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
55+
ifeq ($(ASAN), 1)
56+
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
57+
endif
58+
5659
ifeq ($(OUTPUT),/usr/local)
5760
OUTLIBPATH :=/usr/local
5861
else
@@ -71,7 +74,10 @@ LDFLAGS += -pthread
7174
ifeq ($(ENABLE_FILEWATCHER), 1)
7275
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -ldict -lgevent -lthread -ldarray
7376
endif
74-
#LDFLAGS += -fsanitize=address -static-libasan
77+
78+
ifeq ($(ASAN), 1)
79+
LDFLAGS += -fsanitize=address -static-libasan
80+
endif
7581

7682
###############################################################################
7783
# target

gear-lib/libgevent/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ CFLAGS := -O0 -Wall -Werror -fPIC
4242
LTYPE := release
4343
else
4444
CFLAGS := -g -Wall -Werror -fPIC
45-
# -fsanitize=address -fno-omit-frame-pointer -static-libasan
45+
46+
ifeq ($(ASAN), 1)
47+
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
48+
endif
4649
LTYPE := debug
4750
endif
4851
ifeq ($(OUTPUT),/usr/local)
@@ -58,7 +61,10 @@ SHARED := -shared
5861
LDFLAGS := $($(ARCH)_LDFLAGS)
5962
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lposix -ldarray -lthread
6063
LDFLAGS += -pthread
61-
# -fsanitize=address -static-libasan
64+
65+
ifeq ($(ASAN), 1)
66+
LDFLAGS += -fsanitize=address -static-libasan
67+
endif
6268

6369
###############################################################################
6470
# target

gear-lib/libhal/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ endif
5151
CFLAGS += $($(ARCH)_CFLAGS)
5252
CFLAGS += -I$(OUTPUT)/include/gear-lib
5353

54+
ifeq ($(ASAN), 1)
55+
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
56+
endif
57+
5458
SHARED := -shared
5559

5660
LDFLAGS := $($(ARCH)_LDFLAGS)
5761
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -ldarray -lposix
5862
LDFLAGS += -pthread
5963

64+
ifeq ($(ASAN), 1)
65+
LDFLAGS += -fsanitize=address -static-libasan
66+
endif
67+
6068
###############################################################################
6169
# target
6270
###############################################################################

gear-lib/libhash/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,20 @@ endif
5757
CFLAGS += $($(ARCH)_CFLAGS)
5858
CFLAGS += -I$(OUTPUT)/include/gear-lib
5959

60+
ifeq ($(ASAN), 1)
61+
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
62+
endif
63+
6064
SHARED := -shared
6165

6266
LDFLAGS := $($(ARCH)_LDFLAGS)
63-
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lstrex
67+
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lposix
6468
LDFLAGS += -pthread
6569

70+
ifeq ($(ASAN), 1)
71+
LDFLAGS += -fsanitize=address -static-libasan
72+
endif
73+
6674
###############################################################################
6775
# target
6876
###############################################################################

gear-lib/libipc/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,19 @@ endif
5858
EXTRA_CFLAGS += $($(ARCH)_CFLAGS)
5959
EXTRA_CFLAGS += -I$(OUTPUT)/include/gear-lib
6060

61+
ifeq ($(ASAN), 1)
62+
EXTRA_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
63+
endif
64+
6165
SHARED := -shared
6266

6367
EXTRA_LDFLAGS := $($(ARCH)_LDFLAGS)
6468
EXTRA_LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lposix -ldict -lgevent -ldarray -lthread
6569
EXTRA_LDFLAGS += -pthread -lrt
6670

71+
ifeq ($(ASAN), 1)
72+
EXTRA_LDFLAGS += -fsanitize=address -static-libasan
73+
endif
6774

6875
###############################################################################
6976
# target

gear-lib/liblog/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,21 @@ endif
5151
CFLAGS += $($(ARCH)_CFLAGS)
5252
CFLAGS += -I$(OUTPUT)/include/gear-lib
5353

54+
ifeq ($(ASAN), 1)
55+
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
56+
endif
57+
5458
SHARED := -shared
5559

5660
LDFLAGS := $($(ARCH)_LDFLAGS)
5761
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lposix
5862
LDFLAGS += -pthread
5963

64+
ifeq ($(ASAN), 1)
65+
LDFLAGS += -fsanitize=address -static-libasan
66+
endif
67+
68+
6069
###############################################################################
6170
# target
6271
###############################################################################

gear-lib/libmp4/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ endif
5151
CFLAGS += $($(ARCH)_CFLAGS)
5252
CFLAGS += -I$(OUTPUT)/include/gear-lib
5353

54+
ifeq ($(ASAN), 1)
55+
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
56+
endif
57+
5458
SHARED := -shared
5559

5660
LDFLAGS := $($(ARCH)_LDFLAGS)
5761
LDFLAGS += -pthread
5862
LDFLAGS += -lavcodec -lavformat -lavutil
5963

64+
ifeq ($(ASAN), 1)
65+
LDFLAGS += -fsanitize=address -static-libasan
66+
endif
67+
6068
###############################################################################
6169
# target
6270
###############################################################################

gear-lib/libposix/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ else
5454
CFLAGS := -g -Wall -Werror -fPIC
5555
LTYPE := debug
5656
endif
57+
58+
ifeq ($(ASAN), 1)
59+
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
60+
endif
61+
5762
ifeq ($(OUTPUT),/usr/local)
5863
OUTLIBPATH := /usr/local
5964
else
@@ -67,6 +72,10 @@ SHARED := -shared
6772
LDFLAGS := $($(ARCH)_LDFLAGS)
6873
LDFLAGS += -pthread
6974

75+
ifeq ($(ASAN), 1)
76+
LDFLAGS += -fsanitize=address -static-libasan
77+
endif
78+
7079
###############################################################################
7180
# target
7281
###############################################################################

gear-lib/libposix/libposix.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ typedef struct rational {
219219
#endif
220220
#endif
221221

222+
#define RETURN_IF_FAIL(expr) \
223+
do { \
224+
if (UNLIKELY(expr)) \
225+
return; \
226+
} while(0)
227+
228+
#define RETURN_VAL_IF_FAIL(expr, val) \
229+
do { \
230+
if (UNLIKELY(expr)) \
231+
return (val); \
232+
} while(0)
233+
234+
222235
GEAR_API void *memdup(const void *src, size_t len);
223236
GEAR_API struct iovec *iovec_create(size_t len);
224237
GEAR_API void iovec_destroy(struct iovec *);

0 commit comments

Comments
 (0)