KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build

# The Make variable $(M) must point to the directory that contains the module
# source code (which includes this Makefile). It can either be an absolute or a
# relative path. If it is a relative path, then it must be relative to the
# kernel source directory (KERNEL_SRC). An absolute path can be obtained very
# easily through $(shell pwd). Generating a path relative to KERNEL_SRC is
# difficult and we accept some outside help by letting the caller override the
# variable $(M). Allowing a relative path for $(M) enables us to have the build
# system put output/object files (.o, .ko.) into a directory different from the
# module source directory.
M ?= $(shell pwd)

ENABLE_MULTI_PCIE_CARD ?= n
PCIE_SSID ?= 0x0108

#ifeq ($(WLAN_ROOT),)
# WLAN_ROOT must contain an absolute path (i.e. not a relative path)
#KBUILD_OPTIONS := WLAN_ROOT=$(shell cd $(KERNEL_SRC); readlink -e $(M))
KBUILD_OPTIONS := WLAN_ROOT=$(PWD)
ifeq ($(ENABLE_MULTI_PCIE_CARD), y)
  KBUILD_OPTIONS += MODNAME?=wlan_$(PCIE_SSID)
else
  KBUILD_OPTIONS += MODNAME?=wlan
endif

#By default build for CLD
WLAN_SELECT := CONFIG_QCA_CLD_WLAN=m
KBUILD_OPTIONS += CONFIG_QCA_WIFI_ISOC=0
KBUILD_OPTIONS += CONFIG_QCA_WIFI_2_0=1
KBUILD_OPTIONS += $(WLAN_SELECT)
KBUILD_OPTIONS += $(KBUILD_EXTRA) # Extra config if any
#endif

#common
KBUILD_OPTIONS += CONFIG_NO_USE_BACKPORTS=y CONFIG_CFG80211_DEPEND_ON_KERNEL=y BUILD_DRIVERFW_TOLOCAL=y \
                  CONFIG_CFG80211_INTERNAL_REGDB=y CONFIG_CORE_TECH_DEPEND=y PCIE_CARD_SSID=$(PCIE_SSID)
#qca2066-lea-1-0_qca_standard_oem.git\chss_host_LEA\chss_proc\host\aio-gen\build\scripts\ve-f10\config.ve-f10
KBUILD_OPTIONS += CONFIG_CNSS2=y CONFIG_CNSS_QCA6490=y CONFIG_LINUX_QCMBR=y DEVELOPER_DISABLE_BUILD_TIMESTAMP=y CONFIG_TARGET_11D_SCAN=y CONFIG_FORCE_USER_HINT_CELL_BASE_SELF_MANAGED=y CONFIG_RX_FISA=n CONFIG_WLAN_FEATURE_MBSSID=y CONFIG_FEATURE_FW_LOG_PARSING=y CONFIG_MAX_LOGS_PER_SEC=1000 CONFIG_WLAN_FEATURE_WOW_PULSE=y CONFIG_PCIE_GEN_SWITCH=n CONFIG_PADDR_CHECK_ON_3TH_PLATFORM=y CONFIG_DUMP_LOG_BUF_CNT=128 CONFIG_NON_QC_PLATFORM=y CONFIG_CNSS_UTILS=y CONFIG_WLAN_CLD_DEV_PM_QOS=n CONFIG_MAX_CLIENTS_ALLOWED=64
KBUILD_OPTIONS += CONFIG_FEATURE_ME=y

KBUILD_OPTIONS += CONFIG_DIRECT_BUF_RX_ENABLE=n CONFIG_WMI_DBR_SUPPORT=n CONFIG_WLAN_CFR_ENABLE=n CONFIG_WLAN_ENH_CFR_ENABLE=n CONFIG_WDI3_IPA_OVER_GSI=n CONFIG_FEATURE_EPPING=n CONFIG_DP_MEM_PRE_ALLOC=n CONFIG_WLAN_LOG_ENTER=n CONFIG_WLAN_LOG_EXIT=n CONFIG_WLAN_FEATURE_TWT=n CONFIG_MORE_TX_DESC=n CONFIG_REMOVE_PKT_LOG=y V=1

#Debug options
CONFIG_PERF_BUILD ?= y
#Since MSI-X is supported, ONE_MSI cannot be used. If you set it to "y", Wi-Fi startup will fail.
CONFIG_ONE_MSI_BUILD ?= n
#Only available with "n". Operation with "y" has not been confirmed.
CONFIG_WLAN_RESIDENT_BUILD ?= n

ifeq ($(CONFIG_PERF_BUILD),y)
  ifeq ($(CONFIG_ONE_MSI_BUILD),y)
    KBUILD_OPTIONS += CONFIG_SLUB_DEBUG_ON=n CONFIG_SLUB_DEBUG=n CONFIG_DP_TRACE=n CONFIG_ONE_MSI_VECTOR=y
  else
    KBUILD_OPTIONS += CONFIG_SLUB_DEBUG_ON=n CONFIG_SLUB_DEBUG=n CONFIG_DP_TRACE=n
  endif
else
  ifeq ($(CONFIG_ONE_MSI_BUILD),y)
    KBUILD_OPTIONS += CONFIG_SLUB_DEBUG_ON=y CONFIG_SLUB_DEBUG=y CONFIG_DP_TRACE=y CONFIG_ONE_MSI_VECTOR=y
  else
    ifeq ($(CONFIG_WLAN_RESIDENT_BUILD),y)
      KBUILD_OPTIONS += CONFIG_SLUB_DEBUG_ON=y CONFIG_SLUB_DEBUG=y CONFIG_DP_TRACE=y CONFIG_WLAN_RESIDENT_DRIVER=y
    else
      KBUILD_OPTIONS += CONFIG_SLUB_DEBUG_ON=y CONFIG_SLUB_DEBUG=y CONFIG_DP_TRACE=y
    endif
  endif
endif
ifeq ($(ENABLE_MULTI_PCIE_CARD), y)
  KBUILD_OPTIONS_CLD_3_2 += CLD3_2_MULTI_CARD_KBUILD=CONFIG_WLAN_DISABLE_EXPORT_SYMBOL=y CONFIG_MULTI_CARD=y CONFIG_PCIE_SSID=$(PCIE_SSID) CONFIG_MULTI_IF_LOG=y
endif


export SAP_AUTH_OFFLOAD=1

all:
	$(MAKE) -C $(VOB_KERNEL) M=$(shell pwd) modules $(KBUILD_OPTIONS)

modules:
	$(MAKE) -C $(VOB_KERNEL) M=$(shell pwd) modules $(KBUILD_OPTIONS)

modules_install:
	$(MAKE) INSTALL_MOD_STRIP=1 -C $(VOB_KERNEL) M=$(shell pwd)

clean:
	$(MAKE) -C $(VOB_KERNEL) M=$(shell pwd) clean $(KBUILD_OPTIONS)
