
PREFIX      = ../../install
CROSS       = arm-none-linux-
CROSS_SUP   = arm-linux- arm-none-eabi- aarch64-linux-
GCC         = $(CROSS)gcc
CC          = $(GCC)
CXX         = $(CROSS)g++
OBJDUMP     = $(CROSS)objdump
OBJCOPY     = $(CROSS)objcopy
AR          = $(CROSS)ar

ifneq ($(filter MT6735 MT6292_IA, $(strip $(PLATFORM_CHIP))),)
OFLAGS   = -O2
LOCAL_CFLAGS   = $(BB_CFLAGS_ADD) $(OFLAGS) -g -fPIC
else
OFLAGS   = -O2 -mthumb-interwork
LOCAL_CFLAGS   = $(OFLAGS) -mthumb -g -fPIC
endif
ROOT     = $(PREFIX)/$(CROSS:%-=%)

LOCAL_MODULE = libvendor-ril
LOCAL_PATH   = .
MTK_SHARE_MODEM_CURRENT = 1

COMMON_CFLAGS = -Wall \
                -D_GNU_SOURCE \

SO_CFLAGS_OPTION = -DRIL_SHLIB \

ifeq ($(RAT_CONFIG_C2K_SUPPORT), yes)
    COMMON_CFLAGS += -DC2K_SUPPORT

endif
ifeq ($(MTK_MULTI_SIM_SUPPORT), dsds)
    COMMON_CFLAGS += -DANDROID_SIM_COUNT_2 \
					 -DANDROID_MULTI_SIM \
					 -DMODE_DSDS

endif

ifeq ($(MTK_MULTI_SIM_SUPPORT), dsss)
    COMMON_CFLAGS += -DANDROID_SIM_COUNT_2 \
					 -DANDROID_MULTI_SIM \
					 -DMODE_DSSS

endif

CFLAGS = $(LOCAL_CFLAGS) -std=c99 $(COMMON_CFLAGS) $(SO_CFLAGS_OPTION)
CXXFLAGS = $(LOCAL_CFLAGS) -std=gnu++14 $(COMMON_CFLAGS) $(SO_CFLAGS_OPTION)

LOCAL_C_INCLUDES = -I$(ROOT)/usr/include/binder \
                   -I$(ROOT)/usr/include/utils \
                   -I$(ROOT)/usr/include/glib-2.0 \
                   -I$(ROOT)/usr/include/gio-unix-2.0 \
                   -I$(ROOT)$(libdir)/glib-2.0/include \
                   -I$(ROOT)/usr/include/private \
                   -I$(LOCAL_PATH)/../include \
                   -I$(LOCAL_PATH)/../include/telephony \
                   -I$(LOCAL_PATH)/framework/base \
                   -I$(LOCAL_PATH)/framework/include \
                   -I$(LOCAL_PATH)/framework/include/base \
                   -I$(LOCAL_PATH)/framework/include/core \
                   -I$(LOCAL_PATH)/telephony \
                   -I$(LOCAL_PATH)/telephony/nw \
                   -I$(LOCAL_PATH)/telephony/client \
                   -I$(LOCAL_PATH)/telephony/apn \
                   -I$(LOCAL_PATH)/telephony/oem \
                   -I$(LOCAL_PATH)/telephony/sdk \
                   -I$(LOCAL_PATH)/telephony/suplmessageparser \
                   -I$(LOCAL_PATH)/telephony/data \
                   -I$(LOCAL_PATH)/telephony/agpsadapter \
                   -I$(LOCAL_PATH)/


LOCAL_SRC_FILES_C = \
    ril_callbacks.c \
    atchannel.c \
    misc.c \
    at_tok.c \
    telephony/sdk/Rfx_data_service.c \
    telephony/agpsadapter/protocol/Agps2FrameworkInterface.c \
    telephony/agpsadapter/protocol/Framework2AgpsInterface.c \
    telephony/agpsadapter/protocol/mtk_socket_data_coder.c \
    telephony/agpsadapter/protocol/mtk_socket_utils.c

LOCAL_SRC_FILES_CPP = \
    socket_channel.cpp \
    socket_util.cpp \
    framework/base/RfxVariant.cpp \
    framework/base/RfxMessage.cpp \
    framework/base/RfxSocketState.cpp \
    framework/core/Rfx.cpp \
    framework/core/RfxObject.cpp \
    framework/core/RfxClassInfo.cpp \
    framework/core/RfxAction.cpp \
    framework/core/RfxAsyncSignal.cpp \
    framework/core/RfxSignal.cpp \
    framework/core/RfxTimer.cpp \
    framework/core/RfxMainThread.cpp \
    framework/core/RfxController.cpp \
    framework/core/RfxRootController.cpp \
    framework/core/RfxSlotRootController.cpp \
    framework/core/RfxControllerFactory.cpp \
    framework/core/RfxStatusManager.cpp \
    framework/core/RfxRilAdapter.cpp \
    framework/core/RfxDispatchThread.cpp \
    framework/core/RfxSocketStateManager.cpp \
    framework/base/RfxDebugInfo.cpp \
    framework/base/RfxDefaultDestUtils.cpp \
    framework/base/RfxCallState.cpp \
    framework/base/RfxNwServiceState.cpp \
    framework/core/RfxTestBasicController.cpp \
    framework/core/RfxTestSuitController.cpp \
    framework/base/RfxTransferUtils.cpp \
    framework/base/RfxParcelTransfer.cpp \
    framework/base/RfxParcelTransferUtils.cpp \
    telephony/client/RilClient.cpp \
    telephony/client/RilDefaultClient.cpp \
    telephony/client/RilClientQueue.cpp \
    telephony/client/RpRilClientController.cpp \
    telephony/sdk/RilSdkClient.cpp \
    telephony/sdk/Wrapper.cpp \
    telephony/nw/RpNwStateController.cpp \
    telephony/nw/RpNwPhoneTypeUpdater.cpp \
    telephony/power/RpRadioController.cpp \
    telephony/power/RadioMessage.cpp \
    telephony/call/RpCallController.cpp \
    telephony/ss/RpSsController.cpp \
    telephony/sim/RpSimController.cpp \
    telephony/sim/RpSimControllerBase.cpp \
    telephony/sim/RpGsmSimController.cpp \
    telephony/sim/RpC2kSimController.cpp \
    telephony/apn/RpApnController.cpp \
    telephony/data/RpDataController.cpp \
    telephony/data/RpDataUtils.cpp \
    telephony/data/ApnContext.cpp\
    telephony/data/ApnSetting.cpp\
    telephony/data/RetryManager.cpp\
    telephony/data/Common.cpp\
    telephony/data/NetworkConfig.cpp\
    telephony/data/DcTracker.cpp\
    telephony/data/DcFail.cpp\
    telephony/data/DcController.cpp\
    telephony/data/DataConnection.cpp\
    telephony/data/PdnManager.cpp\
    telephony/data/DataCallResponse.cpp\
    telephony/agpsadapter/RpAgpsNwAdapter.cpp \
    telephony/agpsadapter/RpRilAgpsNwClient.cpp \
    telephony/suplmessageparser/ConcentratedSms.cpp \
    telephony/suplmessageparser/GsmSmsAddress.cpp \
    telephony/suplmessageparser/PduParser.cpp \
    telephony/suplmessageparser/SmsAddress.cpp \
    telephony/suplmessageparser/SmsHeader.cpp \
    telephony/suplmessageparser/SmsMessage.cpp \
    telephony/suplmessageparser/SmsParserUtils.cpp \
    telephony/suplmessageparser/SuplMsgDispatcher.cpp \
    telephony/suplmessageparser/LogUtils.cpp \
    telephony/oem/RpOemController.cpp

LOCAL_OBJ_FILES = $(LOCAL_SRC_FILES_C:.c=.o) $(LOCAL_SRC_FILES_CPP:.cpp=.o)

LOCAL_LIBS := -lcutils -lutils -ldl -llog -lbinder -lpthread -luciwrapper -lrt -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lapn \
                -L../librilproxyutils -lrilproxyutils_static -lpal -lc_dns

LDFLAGS += $(LOCAL_LIBS) \
           $(OFLAGS)

.PHONY: build clean install pack_rootfs haha

all: build


	
$(LOCAL_MODULE).so: $(LOCAL_OBJ_FILES)
	$(warning ########## build $(LOCAL_MODULE).so ##########)
	@rm -f $@
	$(CXX) -shared -Wl,--no-undefined $(LOCAL_LIBS) -o _$@ $^ $(LDFLAGS)
	@mv _$@ $@


%.o: %.c
	$(warning ----->build $<)
	$(CC) $(CFLAGS) $(LOCAL_C_INCLUDES) $(CONFIG) -o $@ -c $<

%.o: %.cpp
	$(warning ----->build $<)
	$(CXX) $(CXXFLAGS) $(LOCAL_C_INCLUDES) $(CONFIG) -o $@ -c $<

build:  $(LOCAL_MODULE).so 
	$(warning ########## build $(LOCAL_MODULE) .so ##########)

clean:
	$(warning ########## clean $(LOCAL_MODULE) ##########)
	-find . -name "*.o" -delete
	-rm $(LOCAL_MODULE).so

install:
	$(warning ########## install $(LOCAL_MODULE) ##########)
	mkdir -p $(ROOT)$(base_libdir)/
	install $(LOCAL_MODULE).so $(ROOT)$(base_libdir)/
	mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk
	cp -af telephony/sdk/data.h  $(ROOT)/$(includedir)/$(NAME)/sdk

pack_rootfs:
	$(warning ########## pack_rootfs $(LOCAL_MODULE) ##########)
	mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/
	cp -af $(LOCAL_MODULE).so $(PACK_INITRAMFS_TO)$(base_libdir)/
	$(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(LOCAL_MODULE).so
	mkdir -p $(PACK_TO)$(base_libdir)/
	cp -af $(LOCAL_MODULE).so $(PACK_TO)$(base_libdir)/
	$(CROSS)strip $(PACK_TO)$(base_libdir)/$(LOCAL_MODULE).so
