SKYNET_ROOT ?= ../../skynet
include $(SKYNET_ROOT)/platform.mk

PLAT ?= none

TARGET =  ../../luaclib/profile.so

GOOGLE_PROFILE_INC ?= /usr/include
GOOGLE_PROFILE_LIB ?= /usr/lib64

ifeq ($(PLAT), macosx)
	CFLAGS = -g -O2 -dynamiclib -Wl,-undefined,dynamic_lookup -DUSE_EXPORT_NAME -DUSE_RDTSC -DUSE_GOOGLE_PROFILER

	GOOGLE_PROFILE_INC = /usr/local/opt/gperftools/include
	GOOGLE_PROFILE_LIB = /usr/local/opt/gperftools/lib
else
ifeq ($(PLAT), linux)
	CFLAGS = -g -O2 -shared -fPIC -DUSE_EXPORT_NAME -DUSE_RDTSC -DUSE_GOOGLE_PROFILER
endif
endif

LUA_LIB ?= $(SKYNET_ROOT)/3rd/lua/
LUA_INC ?= $(SKYNET_ROOT)/3rd/lua/
SKYNET_SRC ?= $(SKYNET_ROOT)/skynet-src

SRC = .

.PHONY: all clean

# 生产环境 最好别用 gperftools
# mac: brew install gperftools
# centos: yum install gperftools yum install gperftools-devel
# https://github.com/google/pprof/blob/master/doc/README.md
# https://gperftools.github.io/gperftools/cpuprofile.html
# https://cloud.tencent.com/developer/article/1433465

# pprof skynet/skynet log/swt.prof --svg (或者 --text)
# pprof --callgrind skynet/skynet log/swt.prof > swt.callgrind
all: $(TARGET)

$(TARGET): $(foreach dir, $(SRC), $(wildcard $(dir)/*.c))
	$(CC) $(CFLAGS) $(SHARED) -I$(LUA_INC) -I$(SKYNET_SRC) -I$(GOOGLE_PROFILE_INC) -L$(GOOGLE_PROFILE_LIB) $^ -o $@ -lprofiler

clean:
	rm -f *.o $(TARGET)