KBUILD_OPTIONS += CAMERA_KERNEL_ROOT=$(shell pwd)
KBUILD_OPTIONS += KERNEL_ROOT=$(ROOT_DIR)/$(KERNEL_DIR)
KBUILD_OPTIONS += INSTALL_MOD_DIR=camera
SUPPORTED_ARCH = qcm6490 qcs9100 qcs615 x1e80100 shikra iq10

.PHONY: clean all

all: modules

CAMERA_COMPILE_TIME = $(shell date)
CAMERA_COMPILE_HOST = $(shell uname -n)
CAMERA_CC_VERSION = $(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1)

cam_generated_h: $(shell find . -iname "*.c") $(shell find . -iname "*.h") $(shell find . -iname "*.mk")
	echo '#define CAMERA_COMPILE_TIME "$(CAMERA_COMPILE_TIME)"' > cam_generated_h
	echo '#define CAMERA_COMPILE_HOST "$(CAMERA_COMPILE_HOST)"' >> cam_generated_h
	echo '#define CAMERA_CC_VERSION "$(CAMERA_CC_VERSION)"' >> cam_generated_h

SRC := $(shell pwd)

modules: cam_generated_h

modules_install:
	@set -e; \
	for arch in $(SUPPORTED_ARCH); do \
		echo "Target: $$arch"; \
		$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules $(KBUILD_OPTIONS) CAMERA_ARCH=$$arch; \
		$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install $(KBUILD_OPTIONS) CAMERA_ARCH=$$arch; \
	done
headers_install:
	echo "Processing target $@"
	KERNEL_SCRIPT=$(KERNEL_SRC) IN_DIR=camera/include/uapi/camera/media/ OUT_DIR=sanitized_headers/camera/media bash scripts/sanitize_uapi.sh
	KERNEL_SCRIPT=$(KERNEL_SRC) IN_DIR=camera_kt/include/uapi/camera/media/ OUT_DIR=sanitized_headers/camera_kt/media bash scripts/sanitize_uapi.sh

%:
	echo "Processing glob target $@"
	@set -e; \
	for arch in $(SUPPORTED_ARCH); do \
		echo "Target: $$arch"; \
		$(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules $(KBUILD_OPTIONS) CAMERA_ARCH=$$arch; \
	done
