Skip to content

Commit

Permalink
1.update build.sh for multi argument parsing
Browse files Browse the repository at this point in the history
2.fix libhash depdency
3.add ASAN check into makefile
  • Loading branch information
gozfree committed Apr 16, 2023
1 parent e646926 commit 5e1947f
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 56 deletions.
114 changes: 65 additions & 49 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,10 @@
set -e

CMD=$0
MODULE=$1
ARCH=$2
MODE=$3

#default is linux
case $# in
0)
MODULE=all;
ARCH=linux;
MODE=debug;;
1)
ARCH=linux;
MODE=debug;;
2)
MODE=debug;;

esac
MODULE=all
ARCH=linux
MODE=debug
ASAN=0


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



usage()
{
echo "==== usage ===="
Expand Down Expand Up @@ -66,26 +55,51 @@ usage()
exit
}

config_linux()
{
CROSS_PREFIX=
}

config_pi()
{
CROSS_PREFIX=arm-linux-gnueabihf-
}

config_android()
{
CROSS_PREFIX=arm-linux-androideabi-
}

config_ios()
{
echo "need a mac computer, who can help me :-)"
exit 0;
}
#-o或--options选项后面接可接受的短选项,如ab:c::,表示可接受的短选项为-a -b -c,其中-a选项不接参数,-b选项后必须接参数,-c选项的参数为可选的
#-l或--long选项后面接可接受的长选项,用逗号分开,冒号的意义同短选项。
#-n选项后接选项解析错误时提示的脚本名字
ARGS=`getopt -o a:m:h --long arch:,module:,help,asan: -n 'build.sh' -- "$@"`
if [ $? != 0 ]; then
echo "Terminating..."
exit 1
fi

#将规范化后的命令行参数分配至位置参数($1,$2,...)
eval set -- "${ARGS}"

while true
do
case "$1" in
-h|--help)
usage;
shift
;;
-a|--arch)
ARCH=$2
shift 2
;;
-m|--mode)
MODE=$2
shift 2
;;
--module)
MODULE=$2
shift 2
;;
--asan)
ASAN=$2
shift 2
;;
--)
shift
break
;;
*)
echo "invalid arguments: $@"
exit 1
;;
esac
done

config_common()
{
Expand All @@ -98,15 +112,21 @@ config_arch()
{
case $ARCH in
"pi")
config_pi;;
CROSS_PREFIX=arm-linux-gnueabihf-
;;
"android")
config_android;;
CROSS_PREFIX=arm-linux-androideabi-
;;
"linux")
config_linux;;
CROSS_PREFIX=
;;
"ios")
config_ios;;
echo "not support cross compile, should compile native on Mac"
exit 0;
;;
*)
usage;;
echo "arch: $ARCH not supported"
;;
esac
}

Expand Down Expand Up @@ -175,12 +195,8 @@ build_module()
;;
*)
echo "==== build ${ARCH} ${MODULE} start..."
MAKE="make ARCH=${ARCH} OUTPUT=${OUTPUT} MODE=${MODE}"
if [[ ${ARCH} == "linux" || ${ARCH} == "pi" || ${ARCH} == "android" ]]; then
${MAKE} > /dev/null
else
echo "${ARCH} not support now" #make -f Makefile.${ARCH} > /dev/null
fi
MAKE="make ARCH=${ARCH} OUTPUT=${OUTPUT} MODE=${MODE} ASAN=${ASAN}"
${MAKE} > /dev/null
if [ $? -ne 0 ]; then
echo "==== build ${ARCH} ${MODULE} failed"
return;
Expand Down
10 changes: 8 additions & 2 deletions gear-lib/libfile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ CFLAGS := -g -Wall -Werror -fPIC
LTYPE := debug
endif

#CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

ifeq ($(OUTPUT),/usr/local)
OUTLIBPATH :=/usr/local
else
Expand All @@ -71,7 +74,10 @@ LDFLAGS += -pthread
ifeq ($(ENABLE_FILEWATCHER), 1)
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -ldict -lgevent -lthread -ldarray
endif
#LDFLAGS += -fsanitize=address -static-libasan

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
Expand Down
10 changes: 8 additions & 2 deletions gear-lib/libgevent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ CFLAGS := -O0 -Wall -Werror -fPIC
LTYPE := release
else
CFLAGS := -g -Wall -Werror -fPIC
# -fsanitize=address -fno-omit-frame-pointer -static-libasan

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif
LTYPE := debug
endif
ifeq ($(OUTPUT),/usr/local)
Expand All @@ -58,7 +61,10 @@ SHARED := -shared
LDFLAGS := $($(ARCH)_LDFLAGS)
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lposix -ldarray -lthread
LDFLAGS += -pthread
# -fsanitize=address -static-libasan

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
Expand Down
8 changes: 8 additions & 0 deletions gear-lib/libhal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(OUTPUT)/include/gear-lib

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

SHARED := -shared

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

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
###############################################################################
Expand Down
10 changes: 9 additions & 1 deletion gear-lib/libhash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(OUTPUT)/include/gear-lib

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

SHARED := -shared

LDFLAGS := $($(ARCH)_LDFLAGS)
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lstrex
LDFLAGS += -L$(OUTLIBPATH)/lib/gear-lib -lposix
LDFLAGS += -pthread

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
###############################################################################
Expand Down
7 changes: 7 additions & 0 deletions gear-lib/libipc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ endif
EXTRA_CFLAGS += $($(ARCH)_CFLAGS)
EXTRA_CFLAGS += -I$(OUTPUT)/include/gear-lib

ifeq ($(ASAN), 1)
EXTRA_CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

SHARED := -shared

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

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

###############################################################################
# target
Expand Down
9 changes: 9 additions & 0 deletions gear-lib/liblog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@ endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(OUTPUT)/include/gear-lib

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

SHARED := -shared

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

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif


###############################################################################
# target
###############################################################################
Expand Down
8 changes: 8 additions & 0 deletions gear-lib/libmp4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(OUTPUT)/include/gear-lib

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

SHARED := -shared

LDFLAGS := $($(ARCH)_LDFLAGS)
LDFLAGS += -pthread
LDFLAGS += -lavcodec -lavformat -lavutil

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
###############################################################################
Expand Down
9 changes: 9 additions & 0 deletions gear-lib/libposix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ else
CFLAGS := -g -Wall -Werror -fPIC
LTYPE := debug
endif

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

ifeq ($(OUTPUT),/usr/local)
OUTLIBPATH := /usr/local
else
Expand All @@ -67,6 +72,10 @@ SHARED := -shared
LDFLAGS := $($(ARCH)_LDFLAGS)
LDFLAGS += -pthread

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
###############################################################################
Expand Down
13 changes: 13 additions & 0 deletions gear-lib/libposix/libposix.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ typedef struct rational {
#endif
#endif

#define RETURN_IF_FAIL(expr) \
do { \
if (UNLIKELY(expr)) \
return; \
} while(0)

#define RETURN_VAL_IF_FAIL(expr, val) \
do { \
if (UNLIKELY(expr)) \
return (val); \
} while(0)


GEAR_API void *memdup(const void *src, size_t len);
GEAR_API struct iovec *iovec_create(size_t len);
GEAR_API void iovec_destroy(struct iovec *);
Expand Down
8 changes: 8 additions & 0 deletions gear-lib/librpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ endif
CFLAGS += $($(ARCH)_CFLAGS)
CFLAGS += -I$(OUTPUT)/include/gear-lib

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

SHARED := -shared

LDFLAGS := $($(ARCH)_LDFLAGS)
Expand All @@ -61,6 +65,10 @@ LDFLAGS += -pthread -lrt
LDFLAGS += -L$(PLATFORM_LIB)
LDFLAGS += $($(ARCH)_LDFLAGS)

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
###############################################################################
Expand Down
8 changes: 8 additions & 0 deletions gear-lib/librtsp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ ifeq ($(ENABLE_LIVEVIEW), 1)
CFLAGS += -DENABLE_LIVEVIEW
endif

ifeq ($(ASAN), 1)
CFLAGS += -fsanitize=address -fno-omit-frame-pointer -static-libasan
endif

SHARED := -shared

LDFLAGS := $($(ARCH)_LDFLAGS)
Expand All @@ -70,6 +74,10 @@ ifeq ($(ENABLE_LIVEVIEW), 1)
LDFLAGS += -lx264 -lavcap
endif

ifeq ($(ASAN), 1)
LDFLAGS += -fsanitize=address -static-libasan
endif

###############################################################################
# target
###############################################################################
Expand Down
Loading

0 comments on commit 5e1947f

Please sign in to comment.