##############################################
# OpenWrt Makefile for bc_bootloader
#
##############################################

include $(TOPDIR)/rules.mk

# Build in kernel build dir
include $(INCLUDE_DIR)/kernel.mk

ifeq ($(PR_NAME),)
$(error PR_NAME should not be empty)
endif

# Name and release number of this package
PKG_NAME:=bc_bootloader
PKG_RELEASE:=1

# this package type is bin not ipkg, no ipk needed
PKG_TARGETS:=bin

# This specifies the directory where we're going to build the program.
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)
# normalboot 和 factoryboot分别在两个子目录下编译
UBOOT_BUILD_DIR:=$(PKG_BUILD_DIR)/uboot
UBOOT_PAD_DIR:=$(PKG_BUILD_DIR)_pad

PKG_SRC_DIR:=$(subst ",,$(CONFIG_BOOT_SRC_DIR))

include $(INCLUDE_DIR)/package.mk

define Package/bc_bootloader
  SECTION:=boot
  CATEGORY:=Boot Loader
  TITLE:=Battery camera bc_bootloader for NVMP
  MENU:=1
endef

NORMAL_BOOT_IMAGE:=$(if $(IMAGE),$(IMAGE),slp-$(BOARD)-$(PROFILE)-uboot.bin)

NORMAL_BOOT_BINARY:=bootloader.bin

ifdef PKG_SRC_DIR
ifeq ($(CONFIG_t23_type),"zn")
BOARD_CONFIG:=isvp_t23n_sfcnor
BOARD_TYPE:=t23
endif
ifeq ($(CONFIG_t32_type),"zl")
BOARD_CONFIG:=PRJ007_zl_sfcnor
BOARD_TYPE:=t32
endif
endif

# Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default.  The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
define Build/Prepare
	rm -f __sdk_depend_dir __iq_depend_dir
	ln -sf $(PKG_SRC_DIR) __sdk_depend_dir
	ln -sf $(T_PRODUCT_CONFIG_DIR)/$(PR_NAME)/IQ __iq_depend_dir
	mkdir -p $(UBOOT_BUILD_DIR)
	$(CP) $(strip $(PKG_SRC_DIR))/u-boot/* $(UBOOT_BUILD_DIR)/
endef

define Build/Compile
	$(MAKE) -C $(UBOOT_BUILD_DIR) $(BOARD_CONFIG) V=1;
endef

define Package/bc_bootloader/install

endef

$(eval $(call BuildPackage,bc_bootloader))
