acl/lib_fiber/c/Makefile

300 lines
7.6 KiB
Makefile
Raw Normal View History

2016-06-24 10:39:05 +08:00
SHELL = /bin/sh
CC = gcc
#CC = g++
CC = ${ENV_CC}
AR = ${ENV_AR}
ARFL = rv
#ARFL = cru
RANLIB = ${ENV_RANLIB}
2023-01-12 17:50:40 +08:00
#JMP_CTX = USE_CONTEXT
JMP_CTX = USE_JMP_DEF
#JMP_CTX = USE_BOOST_JMP
2023-04-26 14:11:40 +08:00
#JMP_CTX = USE_JMP_SYS
2016-06-24 10:39:05 +08:00
CFLAGS = -c -g -W \
-std=gnu99 \
-fPIC \
2016-06-24 10:39:05 +08:00
-Wall \
-Wpointer-arith \
-Wshadow \
-D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS \
-D_USE_FAST_MACRO \
-Wno-long-long \
-Wmissing-prototypes \
-Wcast-qual \
2019-07-31 22:00:41 +08:00
-DUSE_FAST_RING \
-O3 \
-DUSE_CLOCK_GETTIME \
2022-04-07 09:31:37 +08:00
#-DUSE_VALGRIND \
2022-04-09 20:02:58 +08:00
#-DUSE_INLINE_MEMCPY\
2022-03-08 18:12:04 +08:00
#-DUSE_FAST_TIME \
2020-09-26 23:14:11 +08:00
#-Waggregate-return \
2019-08-16 18:17:11 +08:00
#-DDEBUG_MEM \
2018-02-07 19:19:31 +08:00
#-I/usr/local/include
2017-12-21 18:55:50 +08:00
#-DUSE_PRINTF_MACRO
2016-06-24 10:39:05 +08:00
#-Wno-clobbered
#-pedantic
# -Wcast-align
#CFLAGS = -c -g -W -Wall -Wcast-qual -Wcast-align \
#-Waggregate-return -Wmissing-prototypes \
#-Wpointer-arith -Werror -Wshadow -O2 \
#-D_POSIX_PTHREAD_SEMANTICS -D_USE_FAST_MACRO
###########################################################
#Check system:
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB =
CHECKSYSRES = @echo "Unknow system type!";exit 1
UNIXNAME = $(shell uname -sm)
UNIXTYPE = LINUX
ifeq ($(CC),)
CC = gcc
endif
ifeq ($(AR),)
AR = ar
endif
ifeq ($(RANLIB),)
RANLIB = ranlib
endif
2022-01-28 03:37:10 +08:00
ifeq ($(findstring Alpine, $(shell uname -a)), Alpine)
CFLAGS += -DALPINE
endif
2016-06-24 10:39:05 +08:00
ifeq ($(findstring gcc, $(CC)), gcc)
CFLAGS += -Wstrict-prototypes
GCC_VERSION=$(shell gcc --version | grep ^gcc | sed 's/^.* //g')
GCC_MAJOR:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f1)
GCC_MINOR:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f2)
GCC_SUB:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f3)
GCC_VER:=$(shell [ $(GCC_MAJOR) -gt 4 -o \( $(GCC_MAJOR) -eq 4 -a $(GCC_MINOR) -gt 4 \) ] && echo true)
# ifeq ($(GCC_VER), true)
# CFLAGS += -Wno-implicit-fallthrough
# CFLAGS += -Wno-absolute-value
# endif
2016-06-24 10:39:05 +08:00
endif
ifeq ($(findstring clang, $(CC)), clang)
CFLAGS += -Wstrict-prototypes \
-Wno-invalid-source-encoding \
-Wno-invalid-offsetof
2016-06-24 10:39:05 +08:00
endif
ifeq ($(findstring clang++, $(CC)), clang++)
CFLAGS += -Wno-invalid-source-encoding \
-Wno-invalid-offsetof
2016-06-24 10:39:05 +08:00
endif
2022-06-02 23:04:15 +08:00
ifeq ($(findstring arm64, $(UNIXNAME)), arm64)
JMP_CTX = USE_BOOST_JMP
endif
ifeq ($(findstring arm32, $(UNIXNAME)), arm32)
JMP_CTX = USE_BOOST_JMP
endif
2022-06-02 23:06:53 +08:00
ifeq ($(findstring arm, $(UNIXNAME)), arm)
JMP_CTX = USE_BOOST_JMP
endif
2016-06-24 10:39:05 +08:00
# For FreeBSD
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
UNIXTYPE = FREEBSD
endif
# For Darwin
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
# CC += -arch x86_64 -arch arm64
2016-06-24 10:39:05 +08:00
CFLAGS += -DMACOSX -Wno-invalid-source-encoding \
2020-02-15 19:26:41 +08:00
-Wno-invalid-offsetof \
2018-04-22 23:46:17 +08:00
-Wno-deprecated-declarations
2016-06-24 10:39:05 +08:00
endif
# For Linux
ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
UNIXTYPE = LINUX
2022-04-11 14:59:02 +08:00
CFLAGS += -DSHARE_STACK
2022-10-30 17:48:23 +08:00
ifeq ($(HOOK_MMSG_UBUNTU), yes)
CFLAGS += -DHOOK_MMSG_UBUNTU
endif
ifeq ($(HOOK_MMSG_CENTOS), yes)
CFLAGS += -DHOOK_MMSG_CENTOS
endif
2023-02-14 16:36:24 +08:00
# If HAS_IO_URING=yes or has_io_uring=yes has been set in environment,
# or you run "$make HAS_IO_URING=yes", the io_uring engine will be used.
2022-10-30 17:48:23 +08:00
# will use io_uring.
ifeq ($(HAS_IO_URING), yes)
CFLAGS += -DHAS_IO_URING
endif
ifeq ($(has_io_uring), yes)
CFLAGS += -DHAS_IO_URING
endif
ifeq ($(HAS_STATX), yes)
CFLAGS += -DHAS_STATX
endif
ifeq ($(HAS_RENAMEAT2), yes)
CFLAGS += -DHAS_RENAMEAT2
endif
ifeq ($(DEBUG_STACK), yes)
CFLAGS += -DDEBUG_STACK
endif
ifeq ($(debug_stack), yes)
CFLAGS += -DDEBUG_STACK
endif
2016-06-24 10:39:05 +08:00
endif
2022-08-06 20:03:51 +08:00
# For CYGWIN
ifeq ($(findstring CYGWIN, $(UNIXNAME)), CYGWIN)
CFLAGS += -DLINUX2 -DMINGW
endif
2016-06-24 10:39:05 +08:00
# For MINGW
ifeq ($(findstring MINGW, $(UNIXNAME)), MINGW)
CFLAGS += -DLINUX2 -DMINGW
endif
2017-02-21 22:35:31 +08:00
# For MSYS
ifeq ($(findstring MSYS, $(UNIXNAME)), MSYS)
CFLAGS += -DLINUX2 -DMINGW
endif
2016-06-24 10:39:05 +08:00
# For SunOS
ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
ifeq ($(findstring 86, $(UNIXNAME)), 86)
SYSLIB = -lsocket -lnsl -lrt
endif
ifeq ($(findstring sun4u, $(UNIXNAME)), sun4u)
SYSLIB = -lsocket -lnsl -lrt
endif
CFLAGS += -DSUNOS5
2016-06-24 10:39:05 +08:00
UNIXTYPE = SUNOS5
endif
# For HP-UX
ifeq ($(findstring HP-UX, $(UNIXNAME)), HP-UX)
CFLAGS += -DHP_UX -DHPUX11
2016-06-24 10:39:05 +08:00
UNIXTYPE = HPUX
endif
# set which jump lib should be used
CFLAGS += -D$(JMP_CTX)
2016-06-24 10:39:05 +08:00
#Find system type.
ifneq ($(SYSPATH),)
CHECKSYSRES = @echo "System is $(shell uname -sm)"
endif
2016-06-24 10:39:05 +08:00
###########################################################
LIB_PATH_DST = ../lib
OBJ_PATH_DST = ./debug
SRC_PATH_SRC = ./src
INC_COMPILE = -I./include -I./src -I./src/common
2016-06-24 10:39:05 +08:00
CFLAGS += $(INC_COMPILE)
#Project's objs
SRC = $(wildcard $(SRC_PATH_SRC)/*.c) \
$(wildcard $(SRC_PATH_SRC)/common/*.c) \
$(wildcard $(SRC_PATH_SRC)/dns/*.c) \
2017-12-30 23:39:53 +08:00
$(wildcard $(SRC_PATH_SRC)/fiber/*.c) \
$(wildcard $(SRC_PATH_SRC)/event/*.c) \
2022-11-06 22:21:53 +08:00
$(wildcard $(SRC_PATH_SRC)/hook/*.c) \
$(wildcard $(SRC_PATH_SRC)/sync/*.c)
2016-06-24 10:39:05 +08:00
2020-09-26 23:14:11 +08:00
#ASM_OBJ=$(OBJ_PATH_DST)/setjmp.o $(OBJ_PATH_DST)/make_gas.o $(OBJ_PATH_DST)/jump_gas.o
ASM_OBJ=$(OBJ_PATH_DST)/make_gas.o $(OBJ_PATH_DST)/jump_gas.o
OBJ = $(patsubst %.c, $(OBJ_PATH_DST)/%.o, $(notdir $(SRC))) $(ASM_OBJ)
2016-06-24 10:39:05 +08:00
###########################################################
STATIC_LIBNAME = libfiber.a
SHARED_LIBNAME = libfiber.so
STATIC_OLD_LIBNAME = lib_fiber.a
SHARED_OLD_LIBNAME = lib_fiber.so
2016-06-24 10:39:05 +08:00
###########################################################
.PHONY = static shared clean
COMPILE = $(CC) $(CFLAGS) -O3
COMPILE_FIBER = $(CC) $(CFLAGS)
2016-06-24 10:39:05 +08:00
all: static shared
2016-07-15 21:04:01 +08:00
rebuild rb: clean all
2016-06-24 10:39:05 +08:00
$(shell mkdir -p $(OBJ_PATH_DST))
static: $(OBJ)
@echo 'creating $(LIB_PATH_DST)/$(STATIC_LIBNAME)'
$(AR) $(ARFL) $(LIB_PATH_DST)/$(STATIC_LIBNAME) $(OBJ)
$(RANLIB) $(LIB_PATH_DST)/$(STATIC_LIBNAME)
@(cd $(LIB_PATH_DST); rm -f ${STATIC_OLD_LIBNAME}; \
ln -s $(STATIC_LIBNAME) ${STATIC_OLD_LIBNAME})
2016-06-24 10:39:05 +08:00
@echo 'build $(LIB_PATH_DST)/$(STATIC_LIBNAME) ok!'
shared_ldflags = -lrt -lpthread
2016-06-24 10:39:05 +08:00
shared: $(OBJ)
@echo ''
@echo 'creating $(SHARED_LIBNAME)'
@if test -n "$(rpath)" && test "$(UNIXTYPE)" = "LINUX"; then \
echo "building for linux"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJ) \
-L$(rpath) $(shared_ldflags) -Wl,-rpath,$(rpath); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "SUNOS5"; then \
echo "building for sunos5"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJ) \
-R$(rpath) -L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "MACOSX"; then \
echo "building for Darwin"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJ) \
-R$(rpath) -L$(rpath) -lpthread; \
2016-06-24 10:39:05 +08:00
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "FREEBSD"; then \
echo "building for FreeBSD"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJ) \
-R$(rpath) -L$(rpath) -lpthread; \
2016-06-24 10:39:05 +08:00
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
else \
echo 'skip build $(SHARED_LIBNAME); usage: make shared rpath=xxx'; \
fi
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/%.c
$(COMPILE) $< -o $@
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/common/%.c
$(COMPILE) $< -o $@
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/dns/%.c
$(COMPILE) $< -o $@
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/fiber/%.c
$(COMPILE) $< -o $@
2020-09-26 23:14:11 +08:00
#$(OBJ_PATH_DST)/setjmp.o: $(SRC_PATH_SRC)/fiber/exp/setjmp.S
# $(COMPILE) $< -o $@
$(OBJ_PATH_DST)/make_gas.o: $(SRC_PATH_SRC)/fiber/boost/make_gas.S
$(COMPILE) $< -o $@
$(OBJ_PATH_DST)/jump_gas.o: $(SRC_PATH_SRC)/fiber/boost/jump_gas.S
$(COMPILE) $< -o $@
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/event/%.c
$(COMPILE) $< -o $@
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/hook/%.c
2016-06-24 10:39:05 +08:00
$(COMPILE) $< -o $@
2022-11-07 18:28:28 +08:00
$(OBJ_PATH_DST)/%.o: $(SRC_PATH_SRC)/sync/%.c
$(COMPILE) $< -o $@
2016-06-24 10:39:05 +08:00
2016-07-15 21:04:01 +08:00
clean cl:
rm -f $(LIB_PATH_DST)/${STATIC_LIBNAME}
rm -f $(LIB_PATH_DST)/${SHARED_LIBNAME}
rm -f $(LIB_PATH_DST)/${STATIC_OLD_LIBNAME}
rm -f $(LIB_PATH_DST)/${SHARED_OLD_LIBNAME}
2016-06-24 10:39:05 +08:00
rm -f $(OBJ)