include $(RT28xx_DIR)/os/linux/config.mk

#ifdef CONFIG_AP_SUPPORT
ifeq ($(RT28xx_MODE),AP)
MOD_NAME = rt$(MODULE)ap
DAT_PATH = /etc/Wireless/RT$(MODULE_DAT)AP
DAT_FILE_NAME = RT$(MODULE_DAT)AP.dat
endif
#endif // CONFIG_AP_SUPPORT //



#ifdef WAPI_SUPPORT
ifeq ($(HAS_WAPI_SUPPORT),y)
OBJ := -DEXPORT_SYMTAB
endif
#endif // WAPI_SUPPORT //

OBJ := $(MOD_NAME).o

#ifdef CONFIG_AP_SUPPORT
RT28XX_AP_OBJ := \
	$(RT28xx_DIR)/common/crypt_md5.o\
	$(RT28xx_DIR)/common/crypt_sha2.o\
	$(RT28xx_DIR)/common/crypt_hmac.o\
	$(RT28xx_DIR)/common/crypt_aes.o\
	$(RT28xx_DIR)/common/crypt_arc4.o\
	$(RT28xx_DIR)/common/mlme.o\
	$(RT28xx_DIR)/common/cmm_wep.o\
	$(RT28xx_DIR)/common/action.o\
	$(RT28xx_DIR)/common/cmm_data.o\
	$(RT28xx_DIR)/common/rtmp_init.o\
	$(RT28xx_DIR)/common/rtmp_init_inf.o\
	$(RT28xx_DIR)/common/cmm_tkip.o\
	$(RT28xx_DIR)/common/cmm_aes.o\
	$(RT28xx_DIR)/common/cmm_sync.o\
	$(RT28xx_DIR)/common/eeprom.o\
	$(RT28xx_DIR)/common/cmm_sanity.o\
	$(RT28xx_DIR)/common/cmm_info.o\
	$(RT28xx_DIR)/common/cmm_cfg.o\
	$(RT28xx_DIR)/common/cmm_wpa.o\
	$(RT28xx_DIR)/common/dfs.o\
	$(RT28xx_DIR)/common/spectrum.o\
	$(RT28xx_DIR)/common/rtmp_timer.o\
	$(RT28xx_DIR)/common/rt_channel.o\
	$(RT28xx_DIR)/common/cmm_profile.o\
	$(RT28xx_DIR)/common/cmm_asic.o\
	$(RT28xx_DIR)/common/cmm_cmd.o\
	$(RT28xx_DIR)/rate_ctrl/ra_ctrl.o\
	$(RT28xx_DIR)/rate_ctrl/alg_legacy.o\
	$(RT28xx_DIR)/os/linux/rt_profile.o\
	$(RT28xx_DIR)/ap/ap_mbss.o\
	$(RT28xx_DIR)/chips/rtmp_chip.o\
	$(RT28xx_DIR)/ap/ap.o\
	$(RT28xx_DIR)/ap/ap_assoc.o\
	$(RT28xx_DIR)/ap/ap_auth.o\
	$(RT28xx_DIR)/ap/ap_connect.o\
	$(RT28xx_DIR)/ap/ap_mlme.o\
	$(RT28xx_DIR)/ap/ap_sanity.o\
	$(RT28xx_DIR)/ap/ap_sync.o\
	$(RT28xx_DIR)/ap/ap_wpa.o\
	$(RT28xx_DIR)/ap/ap_data.o\
	$(RT28xx_DIR)/common/uapsd.o\
	$(RT28xx_DIR)/ap/ap_autoChSel.o\
	$(RT28xx_DIR)/ap/ap_qload.o\
	$(RT28xx_DIR)/ap/ap_cfg.o

ifeq ($(OSABL),NO)
RT28XX_AP_OBJ := \
	$(RT28xx_DIR)/ap/ap_mbss_inf.o\
	$(RT28xx_DIR)/common/rt_os_util.o\
	$(RT28xx_DIR)/os/linux/ap_ioctl.o\
	$(RT28xx_DIR)/os/linux/rt_linux.o\
	$(RT28xx_DIR)/os/linux/rt_main_dev.o
else
RT28XX_AP_OBJ := \
	$(RT28xx_DIR)/os/linux/rt_symb.o
endif

ifeq ($(HAS_NEW_RATE_ADAPT_SUPPORT),y)
RT28XX_AP_OBJS += $(RT28xx_DIR)/rate_ctrl/alg_grp.o
endif

#ifdef DOT11_N_SUPPORT
ifeq ($(HAS_DOT11_N_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/ba_action.o

endif
#endif // DOT11_N_SUPPORT //

#ifdef BG_FT_SUPPORT
ifeq ($(OSABL),NO)
ifeq ($(HAS_BGFP_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/os/linux/br_ftph.o
endif
endif
#endif // BG_FT_SUPPORT //

#ifdef LED_CONTROL_SUPPORT
ifeq ($(HAS_LED_CONTROL_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/rt_led.o
endif
#endif // LED_CONTROL_SUPPORT //












#ifdef RTMP_MAC_PCI
#endif // RTMP_MAC_PCI //


ifeq ($(HAS_RT2880_RT2860_COEXIST),y)	
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/os/linux/rt_pci_rbus.o\
	$(RT28xx_DIR)/os/linux/rt_rbus_pci_util.o\
	$(RT28xx_DIR)/os/linux/pci_main_dev.o\
	$(RT28xx_DIR)/common/dfs.o
endif

ifeq ($(HAS_ATE),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/ate/common/rt_ate.o
endif

ifeq ($(HAS_QA_SUPPORT),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/ate/common/rt_qa.o
endif

#ifdef WSC_INCLUDED
ifeq ($(HAS_WSC),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/wsc.o\
	$(RT28xx_DIR)/common/wsc_tlv.o\
	$(RT28xx_DIR)/common/wsc_ufd.o\
	$(RT28xx_DIR)/common/crypt_biginteger.o\
	$(RT28xx_DIR)/common/crypt_dh.o
endif
ifeq ($(HAS_WSC_V2),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/common/wsc_v2.o
endif
ifeq ($(HAS_WSC_NFC),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/common/nfc.o
endif
#endif // WSC_INCLUDED //



ifeq ($(HAS_WDS),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/ap/ap_wds.o

ifeq ($(OSABL),NO)
RT28XX_AP_OBJ += \
	../../ap/ap_wds_inf.o
endif
endif

#ifdef APCLI_SUPPORT
ifeq ($(HAS_APCLI),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/ap/ap_apcli.o \
	$(RT28xx_DIR)/ap/apcli_ctrl.o \
	$(RT28xx_DIR)/ap/apcli_sync.o \
	$(RT28xx_DIR)/ap/apcli_auth.o \
	$(RT28xx_DIR)/ap/apcli_assoc.o \
	$(RT28xx_DIR)/common/cmm_mat.o \
	$(RT28xx_DIR)/common/cmm_mat_iparp.o \
	$(RT28xx_DIR)/common/cmm_mat_pppoe.o \
	$(RT28xx_DIR)/common/cmm_mat_ipv6.o

ifeq ($(OSABL),NO)
RT28XX_AP_OBJ += \
	../../ap/ap_apcli_inf.o
endif
endif
#endif // APCLI_SUPPORT //

ifeq ($(HAS_BLOCK_NET_IF),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/common/netif_block.o
endif

ifeq ($(HAS_IGMP_SNOOP_SUPPORT),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/common/igmp_snoop.o
endif


ifeq ($(HAS_QOS_DLS_SUPPORT),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/ap/ap_dls.o
endif

ifeq ($(HAS_IDS_SUPPORT),y)
RT28XX_AP_OBJ += $(RT28xx_DIR)/ap/ap_ids.o
endif

ifeq ($(PLATFORM),IKANOS_V160)
RT28XX_AP_OBJ += $(RT28xx_DIR)/os/linux/vr_ikans.o
endif

ifeq ($(PLATFORM),IKANOS_V180)
RT28XX_AP_OBJ += $(RT28xx_DIR)/os/linux/vr_ikans.o
endif


#ifdef WAPI_SUPPORT
ifeq ($(HAS_WAPI_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/wapi.o
endif
#endif // WAPI_SUPPORT //

#ifdef DOT11R_FT_SUPPORT
ifeq ($(HAS_DOT11R_FT_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/ft.o\
	$(RT28xx_DIR)/common/ft_tlv.o\
	$(RT28xx_DIR)/common/ft_iocl.o\
	$(RT28xx_DIR)/common/ft_rc.o\
	$(RT28xx_DIR)/ap/ap_ftkd.o
endif
#endif // DOT11R_FT_SUPPORT //

#ifdef DOT11K_RRM_SUPPORT
ifeq ($(HAS_DOT11K_RRM_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/rrm_tlv.o \
	$(RT28xx_DIR)/common/rrm_sanity.o \
	$(RT28xx_DIR)/common/rrm.o
endif
#endif // DOT11K_RRM_SUPPORT //

#ifdef DOT11W_PMF_SUPPORT
ifeq ($(HAS_DOT11W_PMF_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/pmf.o
endif
#endif // DOT11W_PMF_SUPPORT //

ifeq ($(HAS_CLIENT_WDS_SUPPORT),y)
RT28XX_AP_OBJ += \
	$(RT28xx_DIR)/common/client_wds.o
endif
#endif // CONFIG_AP_SUPPORT //



PHONY := all release clean install uninstall

all:$(OBJ)

rt$(MODULE)sta.o: $(RT28XX_STA_OBJ)
	$(LD) -r $^ -o $@

rt$(MODULE)ap.o: $(RT28XX_AP_OBJ)
	$(LD) -r $^ -o $@

rt$(MODULE)apsta.o: $(RT28XX_APSTA_OBJ)
	$(LD) -r $^ -o $@

release:
	echo "MAKE Linux Station Code Release"

clean:
	rm -f $(RT28xx_DIR)/common/*.o
	rm -f $(RT28xx_DIR)/common/.*.{cmd,flags,d}
	rm -f $(RT28xx_DIR)/os/linux/*.{o,ko,mod.{o,c}}
	rm -f $(RT28xx_DIR)/os/linux/.*.{cmd,flags,d}
	rm -fr $(RT28xx_DIR)/os/linux/.tmp_versions
	rm -f $(RT28xx_DIR)/chips/*.o
	rm -f $(RT28xx_DIR)/chips/.*.{cmd,flags,d}
ifeq ($(RT28xx_MODE),AP)
	rm -f $(RT28xx_DIR)/ap/*.o
	rm -f $(RT28xx_DIR)/ap/.*.{cmd,flags,d}
else
ifeq ($(RT28xx_MODE),STA)
	rm -f $(RT28xx_DIR)/sta/*.o
	rm -f $(RT28xx_DIR)/sta/.*.{cmd,flags,d}
else
ifeq ($(RT28xx_MODE),APSTA)
	rm -f $(RT28xx_DIR)/ap/*.o
	rm -f $(RT28xx_DIR)/ap/.*.{cmd,flags,d}
	rm -f $(RT28xx_DIR)/sta/*.o
	rm -f $(RT28xx_DIR)/sta/.*.{cmd,flags,d}
endif
endif
endif

install:
	rm -rf $(DAT_PATH)
	$(shell [ ! -f /etc/Wireless ] && mkdir /etc/Wireless)
	mkdir $(DAT_PATH)
	cp $(RT28xx_DIR)/$(DAT_FILE_NAME) $(DAT_PATH)/.
	install -d $(LINUX_SRC_MODULE)
	install -m 644 -c $(addsuffix .o,$(MOD_NAME)) $(LINUX_SRC_MODULE)
	/sbin/depmod -a ${shell uname -r}

uninstall:
#	rm -rf $(DAT_PATH)
	rm -rf $(addprefix $(LINUX_SRC_MODULE),$(addsuffix .o,$(MOD_NAME)))
	/sbin/depmod -a ${shell uname -r}

# Declare the contents of the .PHONY variable as phony.  We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)

