acl/lib_fiber/cpp/Makefile

220 lines
5.7 KiB
Makefile
Raw Normal View History

2016-06-24 10:39:05 +08:00
SHELL = /bin/sh
#CC = g++
CC = ${ENV_CPP}
AR = ${ENV_AR}
ARFL = rv
#ARFL = cru
RANLIB = ${ENV_RANLIB}
FLAGS = ${ENV_FLAGS}
CFLAGS = -c -g -W \
2020-05-13 15:42:50 +08:00
-O3 \
-fPIC \
2016-06-24 10:39:05 +08:00
-Wall \
-Werror \
2016-06-24 10:39:05 +08:00
-Wpointer-arith \
-Wshadow \
-D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS \
-Wno-long-long \
-Wformat \
-Winvalid-pch \
-DACL_PREPARE_COMPILE \
-DUSE_SBOX
#-DACL_USE_CPP11 -std=c++11
2016-06-24 10:39:05 +08:00
#-DUSE_DYNAMIC
# -Wcast-align
#-Wcast-qual
#just for freebsd's iconv.h
CFLAGS += -I/usr/local/include -I../../lib_acl/src/master
2016-06-24 10:39:05 +08:00
shared_ldflags = -lacl_cpp -lprotocol -lacl -lz -lpthread
2016-06-24 10:39:05 +08:00
###########################################################
#Check system:
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
SYSLIB =
CHECKSYSRES = @echo "Unknow system type!";exit 1
UNIXNAME = $(shell uname -sm)
2019-06-17 22:31:43 +08:00
OSTYPE = $(shell uname -m)
2016-06-24 10:39:05 +08:00
UNIXTYPE = LINUX
ifeq ($(CC),)
CC = g++
endif
ifeq ($(AR),)
AR = ar
endif
ifeq ($(RANLIB),)
RANLIB = ranlib
endif
ifeq ($(findstring clang++, $(CC)), clang++)
2019-06-17 22:31:43 +08:00
CFLAGS += -Wno-invalid-source-encoding -Wno-invalid-offsetof
2016-06-24 10:39:05 +08:00
endif
2019-06-17 22:31:43 +08:00
ifeq ($(findstring x86_64, $(OSTYPE)), x86_64)
ifeq ($(findstring g++, $(CC)), g++)
GCC_VERSION:=$(shell echo `gcc --version|grep ^gcc|cut -d' ' -f3`)
GCC_MAJOR:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f1)
GCC_MINOR:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f2)
GCC_VER:=$(shell [ $(GCC_MAJOR) -gt 4 -o \( $(GCC_MAJOR) -eq 4 -a $(GCC_MINOR) -ge 7 \) ] && echo true)
ifeq ($(GCC_VER), true)
CFLAGS += -std=c++11 -DACL_USE_CPP11
endif
endif
endif
2016-06-24 10:39:05 +08:00
# For FreeBSD
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
UNIXTYPE = FREEBSD
2019-06-18 14:02:42 +08:00
shared_ldflags = -lacl_cpp -lprotocol -lacl -L/usr/local/lib -liconv -lz -lpthread
2016-06-24 10:39:05 +08:00
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 \
2016-06-24 10:39:05 +08:00
-Wno-unused-private-field
UNIXTYPE = MACOSX
2019-06-18 14:02:42 +08:00
shared_ldflags = -lacl_cpp -lprotocol -lacl -L/usr/lib -liconv -lz -lpthread
2016-06-24 10:39:05 +08:00
endif
# For Linux
ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
UNIXTYPE = LINUX
2019-06-18 14:02:42 +08:00
shared_ldflags = -lacl_cpp -lprotocol -lacl -lrt -lpthread -lz -ldl
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
UNIXTYPE = LINUX
endif
2016-06-24 10:39:05 +08:00
# For MINGW
ifeq ($(findstring MINGW, $(UNIXNAME)), MINGW)
2019-06-17 22:31:43 +08:00
CFLAGS += -DLINUX2 -DMINGW
UNIXTYPE = LINUX
2016-06-24 10:39:05 +08:00
endif
2022-08-06 20:03:51 +08:00
# For MSYS
ifeq ($(findstring MSYS, $(UNIXNAME)), MSYS)
CFLAGS += -DLINUX2 -DMINGW
UNIXTYPE = LINUX
endif
2016-06-24 10:39:05 +08:00
# For SunOS
ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
2019-06-17 22:31:43 +08:00
ifeq ($(findstring 86, $(UNIXNAME)), 86)
SYSLIB = -lsocket -lnsl -lrt
endif
ifeq ($(findstring sun4u, $(UNIXNAME)), sun4u)
SYSLIB = -lsocket -lnsl -lrt
endif
CFLAGS += -DSUNOS5
UNIXTYPE = SUNOS5
2016-06-24 10:39:05 +08:00
endif
# For HP-UX
ifeq ($(findstring HP-UX, $(UNIXNAME)), HP-UX)
2019-06-17 22:31:43 +08:00
CFLAGS += -DHP_UX -DHPUX11
UNIXTYPE = HPUX
2016-06-24 10:39:05 +08:00
endif
#Find system type.
ifneq ($(SYSPATH),)
2019-06-17 22:31:43 +08:00
CHECKSYSRES = @echo "System is $(shell uname -sm)"
2016-06-24 10:39:05 +08:00
endif
###########################################################
OBJ_PATH_DST = ./debug
LIB_PATH_DST = ../lib
CFLAGS += -I./src -I../c/include -I./include -I../../lib_acl/include -I../../lib_acl_cpp/include
#Project's objs
2021-08-18 16:32:34 +08:00
SRC = $(wildcard src/*.cpp) $(wildcard src/keeper/*.cpp)
OBJ = $(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(SRC)))
2016-06-24 10:39:05 +08:00
###########################################################
.PHONY = static shared clean
VERSION = 0.9
DATE_NOW = 20`date +%y`.`date +%m`.`date +%d`
STATIC_LIBNAME = libfiber_cpp.a
SHARED_LIBNAME = libfiber_cpp.so
STATIC_OLD_LIBNAME = lib_fiber_cpp.a
SHARED_OLD_LIBNAME = lib_fiber_cpp.so
2016-06-24 10:39:05 +08:00
lib: static
all: static shared sample
$(shell mkdir -p $(OBJ_PATH_DST))
2016-06-24 10:39:05 +08:00
COMPILE = $(CC) $(CFLAGS)
COMPILE_OBJ = @(echo 'building $<'; $(COMPILE) $< -o $@)
CREATE_DEF = @(echo 'creating $@'; rm -f $@; \
2019-06-17 22:31:43 +08:00
$(COMPILE) -MM $< > $@.$$$$; \
sed 's,.*.o\( \)*:,$(patsubst %.inc,%.o,$@) $@ :,g' < $@.$$$$ > $@; \
rm -f $@.$$$$)
2016-06-24 10:39:05 +08:00
###########################################################
sample: static
@(cd samples; make)
static: $(OBJ)
2016-06-24 10:39:05 +08:00
@echo 'creating $(LIB_PATH_DST)/$(STATIC_LIBNAME)'
@$(AR) $(ARFL) $(LIB_PATH_DST)/$(STATIC_LIBNAME) $(OBJ)
2016-06-24 10:39:05 +08:00
@$(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 'create $(LIB_PATH_DST)/$(STATIC_LIBNAME) ok!'
shared: $(OBJ)
2016-06-24 10:39:05 +08:00
@echo 'creating $(SHARED_LIBNAME)'
@if test -n "$(rpath)" && test "$(UNIXTYPE)" = "LINUX"; then \
echo "building for linux"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJ) \
2016-06-24 10:39:05 +08:00
-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) \
2016-06-24 10:39:05 +08:00
-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) \
2016-06-24 10:39:05 +08:00
-R$(rpath) -L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
elif test -n "$(rpath)" && test "$(UNIXTYPE)" = "FREEBSD"; then \
echo "building for Darwin"; \
$(CC) -shared -o $(rpath)/$(SHARED_LIBNAME) $(OBJ) \
2016-06-24 10:39:05 +08:00
-R$(rpath) -L$(rpath) $(shared_ldflags); \
echo 'build $(rpath)/$(SHARED_LIBNAME) ok!'; \
else \
echo 'skip build $(SHARED_LIBNAME); usage: make shared rpath=xxx'; \
fi
# src
$(OBJ_PATH_DST)/%.o: ./src/%.cpp
$(COMPILE_OBJ)
2016-01-14 14:45:37 +08:00
$(OBJ_PATH_DST)/%.o: ./src/keeper/%.cpp
$(COMPILE_OBJ)
2016-06-24 10:39:05 +08:00
2017-11-24 11:10:44 +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}
rm -f $(OBJ)
2016-06-24 10:39:05 +08:00
rebuild rb: clean static