# SPDX-License-Identifier: GPL-2.0-only

obj-m += aml-isp5.o

ccflags-y += -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter

M_PATH := $(shell dirname $(lastword $(MAKEFILE_LIST)))

ifeq ($(DRV_SRC_OBJ),)
	DRV_SRC := $(wildcard *.c hw/*.c)
	export DRV_SRC_OBJ := $(DRV_SRC:.c=.o)
endif

aml-isp5-objs += $(DRV_SRC_OBJ)

LOCAL_INCLUDES := -I$(M_PATH)/ -I$(M_PATH)/hw

ccflags-y += -DA9_CHIP

ccflags-y += -Wno-unused-function
ccflags-y += -Wno-unused-variable

ccflags-y += $(LOCAL_INCLUDES)
ccflags-y += -Wno-declaration-after-statement -Wno-error
EXTRA_CFLAGS += $(LOCAL_INCLUDES)

ifeq ($(O),)
out_dir := .
else
out_dir := $(O)
endif
-include $(out_dir)/include/config/auto.conf

all:
	@$(MAKE) -C $(KERNEL_SRC) M=$(M)  modules
modules_install:
	-include $(OUT_DIR)/include/config/auto.conf
	$(MAKE) INSTALL_MOD_STRIP=1 M=$(M) -C $(KERNEL_SRC) modules_install
	$(Q)mkdir -p $(out_dir)/../vendor_lib
	$(Q)if [ -z "$(CONFIG_AMLOGIC_KERNEL_VERSION)" ]; then \
		cp $(out_dir)/$(M)/*.ko ${out_dir}/../vendor_lib/modules/ ; \
	else \
		find $(INSTALL_MOD_PATH)/lib/modules/*/$(INSTALL_MOD_DIR) -name "*.ko" -exec cp {} $(out_dir)/../vendor_lib/modules/ \; ; \
	fi

clean:
	@$(MAKE) -C $(KERNEL_SRC) M=$(M) clean